#include "word.h"

unsigned Word::readOnly = 4;
_variety_word Word::arrWord[11] = {_identifier,_keyword,_unsigned_int,_delimiter_single_char,_delimiter_double_char,_comment_begin,_comment_end,_string_delimiter,_array_delimiter,_blank,_unknown};
QString Word::strVariety_en[11] = {"ID","标识符子集,内部表示","INTC","单字符界限符",":=","{","}","\'","..","_blank","_unknown"};
QString Word::strVariety_cn[11] = {"标识符","保留字","无符号整数","单字符分界符","双字符分界符","注释头符","注释尾符","字符串起始、结束符","数组下标界限符","空格","未知"};
_variety_word Word::IntToVariety(int n) {
    if(n < 0 || n > _unknown) {
        return _unknown;
    }
    return arrWord[n];
}
QString Word::IntToVarietyString_en(int n) {
    if(n < 0 || n > _unknown) {
        return strVariety_en[_unknown];
    }
    return strVariety_en[n];
}
QString Word::IntToVarietyString_cn(int n) {
    if(n < 0 || n > _unknown) {
        return strVariety_cn[_unknown];
    }
    return strVariety_cn[n];
}

_variety_word Word::String_cnToVariety(QString str)
{
    for(int i = 0;i < 11;i++) {
        if(str == strVariety_cn[i]) {
            return IntToVariety(i);
        }
    }
    return IntToVariety(10);
}
bool Word::ReadOnly(_variety_word w) {
    return (w < readOnly);
}
bool Word::ReadOnly(单词类型 w) {
    return (w < readOnly);
}

Word::Word() {}
Word::Word(_variety_word v,QString s) {
    variety = v;
    content = s;
}
Word::Word(单词类型 v,QString s) {
    variety = arrWord[v];
    content = s;
}

_variety_word Word::GetVariety() {
    return variety;
}
_variety_word Word::GetVariety() const{
    return variety;
}
QString Word::GetContent() {
    return content;
}
QString Word::GetContent() const{
    return content;
}

void Word::SetVariety(_variety_word v) {
    variety = v;
}
void Word::SetVariety(单词类型 v) {
    variety = arrWord[v];
}
void Word::SetContent(QString s) {
    content = s;
}

bool Word::operator<(const Word& other) {
    return (variety < other.GetVariety());
}
bool Word::operator<(const Word& other) const{
    return (variety < other.GetVariety());
}
bool Word::operator==(const Word& other) {
    return (variety == other.GetVariety() && content == other.GetContent());
}
bool Word::operator==(const Word& other) const{
    return (variety == other.GetVariety() && content == other.GetContent());
}
bool Word::operator==(QString value) {
    return (content == value);
}
bool Word::operator==(QString value) const{
    return (content == value);
}

QString Word::GetVarietyString_en () {
    return strVariety_en[variety];
}
QString Word::GetVarietyString_en () const{
    return strVariety_en[variety];
}
QString Word::GetVarietyString_cn () {
    return strVariety_cn[variety];
}
QString Word::GetVarietyString_cn () const{
    return strVariety_cn[variety];
}
